import Vue from 'vue'
import VueRouter from 'vue-router'
import admin from "@/router/admin.js"
import user from "@/router/user.js"
import error from "@/router/error.js"

Vue.use(VueRouter)

// 模块化加载路由
const routes = [
    ...user, 
    ...admin,
    ...error,
]

// vue2中重定向到相同页面的报错，重写其中的回调（不抛出错误异常到控制台)
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}


const router = new VueRouter(
    {
        history: "history",
        routes: routes
    }
)

export default router